home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / internal / m68k / m68k-emul / preparecontext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  1.6 KB  |  78 lines

  1. #include <exec/types.h>
  2. #include <aros/libcall.h>
  3.  
  4. /*****************************************************************************
  5.  
  6.     NAME */
  7.  
  8.     __AROS_LH3I(APTR, PrepareContext,
  9.  
  10. /*  SYNOPSIS */
  11.     __AROS_LA(APTR, stackPointer, A0),
  12.     __AROS_LA(APTR, entryPoint,   A1),
  13.     __AROS_LA(APTR, fallBack,     A2),
  14.  
  15. /*  LOCATION */
  16.     struct ExecBase *, SysBase, 9, Exec)
  17.  
  18. /*  FUNCTION
  19.     Allocates the space required to hold a new set of registers on the
  20.     Stack given by stackPointer and clears the area except for pc which
  21.     is set to the address given by entryPoint.
  22.  
  23.     INPUTS
  24.     stackPointer - Pointer to a scpecific stack
  25.     entryPoint   - Address of the function to call when the new context
  26.                becomes active.
  27.     fallBack     - Address to be called when the entryPoint function ended
  28.                with an rts.
  29.  
  30.     RESULT
  31.     The new Stackpointer with the underlying context.
  32.  
  33.     NOTES
  34.     This function is for internal use by exec only.
  35.  
  36.     This function is processor dependant.
  37.  
  38.     EXAMPLE
  39.  
  40.     BUGS
  41.  
  42.     SEE ALSO
  43.     SwitchTasks()
  44.  
  45.     INTERNALS
  46.  
  47.     HISTORY
  48.  
  49. ******************************************************************************/
  50. {
  51.     __AROS_FUNC_INIT
  52.     UBYTE *sp=(UBYTE *)stackPointer;
  53.     int i;
  54.  
  55.     /*
  56.     mc68000 version. As long as no FPU is in use this works for the
  57.     other mc680xx brands as well.
  58.     */
  59.  
  60.     /* Push fallback address */
  61.     sp-=sizeof(APTR);
  62.     *(APTR *)sp=fallBack;
  63.  
  64.     /* Now push the context. Prepare a rts first (pc). */
  65.     sp-=sizeof(APTR);
  66.     *(APTR *)sp=entryPoint;
  67.  
  68.     /* Push 15 registers */
  69.     for(i=0;i<15;i++)
  70.     {
  71.     sp-=sizeof(LONG);
  72.     *(LONG *)sp=0;
  73.     }
  74.  
  75.     return sp;
  76.     __AROS_FUNC_EXIT
  77. } /* PrepareContext */
  78.